/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package window;

import data.Dinheiro;
import data.Empregado;
import data.Sexo;
import java.util.Calendar;
import util.Util;

/**
 *
 * @author
 * PedroLZ
 */
public class BaseDlgDadosEmpregado extends javax.swing.JDialog
{
	public BaseDlgDadosEmpregado(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
		SupportWindow.centralizaJanela( this );
	}
	
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grpSexo = new javax.swing.ButtonGroup();
        lblTitulo = new javax.swing.JLabel();
        lblObrigatorio = new javax.swing.JLabel();
        pnlDadosPessoais = new javax.swing.JPanel();
        lblCPF = new javax.swing.JLabel();
        txtCPF = new javax.swing.JTextField();
        lblNome = new javax.swing.JLabel();
        txtNome = new javax.swing.JTextField();
        lblSexo = new javax.swing.JLabel();
        lblDataNasc = new javax.swing.JLabel();
        optSexoMasculino = new javax.swing.JRadioButton();
        optSexoFeminino = new javax.swing.JRadioButton();
        txtDataNasc = new javax.swing.JTextField();
        pnlDadosEmpr = new javax.swing.JPanel();
        lblSalario = new javax.swing.JLabel();
        txtSalario = new javax.swing.JTextField();
        lblDataAdmissao = new javax.swing.JLabel();
        lblDataDeslig = new javax.swing.JLabel();
        txtDataAdmissao = new javax.swing.JTextField();
        txtDataDeslig = new javax.swing.JTextField();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        lblTitulo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblTitulo.setText("Dados do Empregado:");

        lblObrigatorio.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblObrigatorio.setText("*Obrigatório.");

        pnlDadosPessoais.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados Pessoais:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.darkGray));

        lblCPF.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblCPF.setText("CPF* (apenas números):");

        txtCPF.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblNome.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblNome.setText("Nome*:");

        txtNome.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblSexo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblSexo.setText("Sexo*:");

        lblDataNasc.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblDataNasc.setText("Data de Nascimento*:");

        grpSexo.add(optSexoMasculino);
        optSexoMasculino.setText("Masculino");

        grpSexo.add(optSexoFeminino);
        optSexoFeminino.setText("Feminino");

        txtDataNasc.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        javax.swing.GroupLayout pnlDadosPessoaisLayout = new javax.swing.GroupLayout(pnlDadosPessoais);
        pnlDadosPessoais.setLayout(pnlDadosPessoaisLayout);
        pnlDadosPessoaisLayout.setHorizontalGroup(
            pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosPessoaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNome)
                    .addComponent(lblCPF)
                    .addComponent(txtCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addGroup(pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDadosPessoaisLayout.createSequentialGroup()
                        .addComponent(lblSexo)
                        .addGap(112, 112, 112))
                    .addGroup(pnlDadosPessoaisLayout.createSequentialGroup()
                        .addComponent(optSexoMasculino)
                        .addGap(18, 18, 18)
                        .addComponent(optSexoFeminino))
                    .addComponent(txtDataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27))
        );
        pnlDadosPessoaisLayout.setVerticalGroup(
            pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosPessoaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCPF)
                    .addComponent(lblDataNasc))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDataNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNome)
                    .addComponent(lblSexo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(optSexoMasculino)
                    .addComponent(optSexoFeminino))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pnlDadosEmpr.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados Empresariais:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.darkGray));

        lblSalario.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblSalario.setText("Salário*:");

        txtSalario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        lblDataAdmissao.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblDataAdmissao.setText("Data de Admissão*:");

        lblDataDeslig.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblDataDeslig.setText("Data de Desligamento:");

        txtDataAdmissao.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        txtDataDeslig.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        javax.swing.GroupLayout pnlDadosEmprLayout = new javax.swing.GroupLayout(pnlDadosEmpr);
        pnlDadosEmpr.setLayout(pnlDadosEmprLayout);
        pnlDadosEmprLayout.setHorizontalGroup(
            pnlDadosEmprLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosEmprLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDadosEmprLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDadosEmprLayout.createSequentialGroup()
                        .addGroup(pnlDadosEmprLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDataAdmissao)
                            .addComponent(txtDataAdmissao, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 113, Short.MAX_VALUE)
                        .addGroup(pnlDadosEmprLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblSalario)
                            .addComponent(txtSalario, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35))
                    .addGroup(pnlDadosEmprLayout.createSequentialGroup()
                        .addComponent(lblDataDeslig)
                        .addContainerGap())
                    .addGroup(pnlDadosEmprLayout.createSequentialGroup()
                        .addComponent(txtDataDeslig, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        pnlDadosEmprLayout.setVerticalGroup(
            pnlDadosEmprLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosEmprLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDadosEmprLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSalario)
                    .addComponent(lblDataAdmissao))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosEmprLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSalario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDataAdmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblDataDeslig)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtDataDeslig, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnCancelar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(pnlDadosPessoais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(pnlDadosEmpr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblTitulo))
                        .addContainerGap(267, Short.MAX_VALUE))))
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(lblObrigatorio)
                .addGap(466, 466, 466)
                .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                .addGap(36, 36, 36))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(lblTitulo)
                .addGap(26, 26, 26)
                .addComponent(pnlDadosPessoais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25)
                .addComponent(pnlDadosEmpr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblObrigatorio)
                        .addGap(27, 27, 27))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
		SupportWindow.fecharDialogo( this );
	}//GEN-LAST:event_btnCancelarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.ButtonGroup grpSexo;
    private javax.swing.JLabel lblCPF;
    private javax.swing.JLabel lblDataAdmissao;
    private javax.swing.JLabel lblDataDeslig;
    private javax.swing.JLabel lblDataNasc;
    private javax.swing.JLabel lblNome;
    private javax.swing.JLabel lblObrigatorio;
    private javax.swing.JLabel lblSalario;
    private javax.swing.JLabel lblSexo;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JRadioButton optSexoFeminino;
    private javax.swing.JRadioButton optSexoMasculino;
    private javax.swing.JPanel pnlDadosEmpr;
    private javax.swing.JPanel pnlDadosPessoais;
    private javax.swing.JTextField txtCPF;
    private javax.swing.JTextField txtDataAdmissao;
    private javax.swing.JTextField txtDataDeslig;
    private javax.swing.JTextField txtDataNasc;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtSalario;
    // End of variables declaration//GEN-END:variables

	//-------------------------------------------------------------------------
	// métodos private
	//-------------------------------------------------------------------------	
	protected Empregado getDadosEmpregado()
	{
		Empregado empregado = new Empregado();
		
		empregado.setCpf( getCPF() );
		empregado.setNome( getNome() );
		empregado.setSexo( getSexo() );
		empregado.setSalario( getSalario() );
		empregado.setDataNascimento( getDataNasc() );
		empregado.setDataAdmissao( getDataAdmissao() );
		empregado.setDataDesligamento( getDataDeslig() );
		
		return empregado;
	}

	private String getCPF() {
		return txtCPF.getText();
	}

	private String getNome() {
		return txtNome.getText();
	}

	private Dinheiro getSalario() {
		return SupportWindow.getParameter( txtSalario.getText(), (Dinheiro)null );
	}

	private Calendar getDataNasc() {
		return SupportWindow.getParameter( txtDataNasc.getText(), (Calendar)null );
	}

	private Calendar getDataAdmissao() {
		return SupportWindow.getParameter( txtDataAdmissao.getText(), (Calendar)null );
	}

	private Calendar getDataDeslig() {
		return SupportWindow.getParameter( txtDataDeslig.getText(), (Calendar)null );
	}

	private Sexo getSexo() {
		if( optSexoMasculino.isSelected() ) 
			return Sexo.MASCULUNO;
		if( optSexoFeminino.isSelected() ) 
			return Sexo.FEMININO;
		else 
			return Sexo.NAO_INFORMADO;
	}
}
